<?php
// +----------------------------------------------------------------------
// | Site:  [ http://www.yzmcms.com]
// +----------------------------------------------------------------------
// | Copyright: 袁志蒙工作室，并保留所有权利
// +----------------------------------------------------------------------
// | Author: YuanZhiMeng <214243830@qq.com>
// +---------------------------------------------------------------------- 
// | Explain: 这不是一个自由软件,您只能在不用于商业目的的前提下对程序代码进行修改和使用，不允许对程序代码以任何形式任何目的的再发布！
// +----------------------------------------------------------------------

defined('IN_YZMPHP') or exit('Access Denied'); 
yzm_base::load_controller('common', 'admin', 0);
yzm_base::load_sys_class('page','',0);
yzm_base::load_common('class/xlswriter.class.php');

class collect extends common {

	/**
	 * 配置信息
	 */
	
	public $config;
	public $data=[];
	public $field_map = [
		'sex' => ['1'=>'男','2'=>'女'],
		'brand' => ['1'=>'增致牛仔','2'=>'Jeep','3'=>'一品天成'],
		'is_diy' => ['1'=>'专版','2'=>'基础','3'=>'公版'],
		'status' => ['1'=>'上架','2'=>'下架'],
		'season' => ['1'=>'春季','2'=>'夏季','3'=>'秋季','4'=>'冬季','5'=>'四季'],
	];
	public function __construct(){
		parent::__construct();
	}
	
	//货盘列表
	public function collect_list() {
		$d_list = D('collect_list');
		$page = input('get.page');
		$limit = input('get.limit');
		if($page){
			$total = $d_list->where('1=1')->total();
			$page = new page($total, $limit);
			$this->data = $d_list->alias('l')->field('l.*,c.m_name')->where('1=1')->join(C('db_prefix').'collect_category c on l.c_id = c.id','left')->limit($page->limit())->select();
			$this->_data_format();
			$data = ['code'=>0,'msg'=>'','count'=>$total,'data'=>$this->data];
			return_json($data);
		}
		include $this->admin_tpl('collect/collect_list');
	}
	
	//供应商列表
	public function collect_supplier(){
		$d_supplier = D('collect_supplier');
		$page = input('get.page');
		$limit = input('get.limit');
		if($page){
			$total = $d_supplier->where('1=1')->total();
			$page = new page($total, $limit);
			$this->data = $d_supplier->where('1=1')->limit($page->limit())->select();
			$data = ['code'=>0,'msg'=>'','count'=>$total,'data'=>$this->data];
			return_json($data);
		}
		include $this->admin_tpl('collect/collect_supplier');
	}
	
	private function _data_format(){
		if(!$this->data){
			return [];
		}
		foreach($this->data as $k=>&$v){
			foreach($v as $key=>&$val){
				if($this->field_map[$key]){
					$val = $this->field_map[$key][$val];
				}
			}
		}
	}
}